package com.lmabbe.common.datasources.converter;

import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DataSourceProperty;
import com.lmabbe.common.global.context.metadata.tenant.Database;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;

/**
 * datesource转换
 *
 * @author lmabbe
 */
@Mapper
public interface DatabaseConverter {

    DatabaseConverter INSTANCE = Mappers.getMapper(DatabaseConverter.class);

    /**
     * 将租户的Database 转成mybatis的DataSourceProperty
     *
     * @param database :
     * @return {@link DataSourceProperty}
     * @date 2022/2/19 3:14 PM
     * @author liming
     */
    @Mappings({
            @Mapping(target = "driverClassName", source = "dsDriverClass"),
            @Mapping(target = "url", source = "dsUrl"),
            @Mapping(target = "username", source = "dsUsername"),
            @Mapping(target = "password", source = "dsPassword"),
            @Mapping(target = "lazy", expression = "java(false)")
    })
    DataSourceProperty converter2Property(Database database);
}
